// standard libraries
#include <string>
#include <cstdio>

// custom libraries
#include "..\..\include\file\filebase.h"
#include "..\..\include\file\infile.h" // matching header


// ==================================
//   CONSTRUCTORS and DESTRUCTORS
// ==================================

InFile::InFile()
{
	// Nothing
}

InFile::InFile(std::string path, FileBase::OpenMode openMode) 
{
    open(path, openMode);
}


// ==================================
//         PUBLIC FUNCTIONS
// ==================================

void InFile::open(std::string path, FileBase::OpenMode openMode)
{
	// Open file in read mode.
	FileBase::open_as(path, openMode);
}

void InFile::read(char* buffer, size_t length)
{
	fread(buffer, 1, length, FileBase::file_);
}

void InFile::seekg(int offset, FileBase::Position origin)
{
	fseek(FileBase::file_, offset, origin);
}

size_t InFile::tellg()
{
	return (size_t)ftell(FileBase::file_);
}


// ==================================
//              FRIENDS
// ==================================

bool getline(InFile& infile, std::string& line)
{
	bool b = false;

	if (infile.is_open()) {
		char c[100];
		b = fgets(c, sizeof c, infile.file_);
		line = c;
	}

	return b;
}
